﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
using My.SharePoint.STSADM.Commands.OperationHelpers;
using My.SharePoint.STSADM.Commands.SPValidators;
using IdeasFree.SharePoint.StsAdm.Commands.Helpers;


namespace IdeasFree.SharePoint.StsAdm.Commands
{
    public class ExportDocument : SPOperation
    {
        public ExportDocument()
        {
            SPParamCollection parameters = new SPParamCollection();
            parameters.Add(new SPParam("url", "url", true, null,new SPUrlValidator() , "Please specify url of the site."));
            parameters.Add(new SPParam("doclib", "doclib", true, null, new SPNonEmptyValidator(), "Please specify source document library."));
            parameters.Add(new SPParam("exportfolder", "exportfolder", true, null, new SPNonEmptyValidator(), "Please specify path to store exported documents."));
            parameters.Add(new SPParam("excludefolder", "excludefolder", false, "Forms", new SPValidator(), "Exclude folder in comma separated. Default: Forms"));
            parameters.Add(new SPParam("metaonly", "metaonly", false, "true", new SPTrueFalseValidator(), "Please specify True or False"));
            parameters.Add(new SPParam("enablews", "enablews", false, "false", new SPTrueFalseValidator(), "Please specify True or False to enable via web service."));

            StringBuilder sb = new StringBuilder();
            sb.Append("-url <full url to a which host the document library> ");
            sb.Append("\r\n\t-doclib <document library name to be exported> ");
            sb.Append("\r\n\t-exportfolder <path to the folder to store exported documents> ");
            sb.Append("\r\n\t-metaonly <Default: true , export only the metadata> ");
            sb.Append("\r\n\t-enablews <Default: false , enable/disable web service call> ");

            sb.Append("\r\n\r\nExport whole structue of document library to a physical folder.");
            Init(parameters, sb.ToString());
        }

        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {

            Operation.ExportDocument(Params, keyValues);
            

            output = "";
            return 1;
        }

        public override string GetHelpMessage(string command)
        {
            return HelpMessage;
        }

    }
}
